package com.szrt.scott.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;
import com.szrt.scott.entity.StudentEntity;

public class JsonServlet extends HttpServlet {

	private static final long serialVersionUID = -7701600088549009605L;
	
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String name=request.getParameter("username");
		String wage=request.getParameter("wage");
		
		System.out.println(name);
		System.out.println(wage);
		
		List<StudentEntity> list = new ArrayList<StudentEntity>();
		StudentEntity student1= new StudentEntity("张无忌",22);
		StudentEntity student2= new StudentEntity("赵敏",33);
		list.add(student1);
		list.add(student2);
		System.out.println("10086");
		Gson json = new Gson();
		
		//把stduent1对象转化成json格式的字符串
		String jieguo = json.toJson(list);
		request.setAttribute("jsonsObjectScott", jieguo);
		
	}

}
